package com.gzsxy.esjy.service.cart.controller;


import com.gzsxy.esjy.bus.log.annotation.OperLog;
import com.gzsxy.esjy.bus.log.enum1.LogActionType;
import com.gzsxy.esjy.service.base.dto.response.CartRsp;
import com.gzsxy.esjy.service.base.dto.response.DefaultResponse;
import com.gzsxy.esjy.service.cart.service.CartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaolong
 * @version 1.0
 * @description: 购物车管理
 * @date 2022/2/17 17:44
 */
@CrossOrigin  //解决跨域
@RefreshScope    //动态刷新配置文件-外部配置文件
@RestController
@RequestMapping("/admin/cart")
@Api("购物车管理")
public class CartController {

    @Autowired
    private CartService cartService;

    @GetMapping("/{userId}")
    @ApiOperation("根据用户id获取当前购物车")
    public DefaultResponse getCartByUserId(@PathVariable String userId){
        List<CartRsp> cartList = cartService.getCartByUserId(userId);
        return DefaultResponse.ok(cartList);
    }

    @GetMapping("/delete/{userId}")
    @ApiOperation("根据用户id清空购物车")
    @OperLog(operModul = "购物车管理",operType = LogActionType.DELETE,operDesc = "根据用户id清空购物车")
    public DefaultResponse deleteByUserId(@PathVariable String userId){
        cartService.deleteByUserId(userId);
        return DefaultResponse.ok();
    }




}
